<?php
//微信用户相关

namespace App\Http\Controllers;

use App\Models\FollowModel;
use Illuminate\Http\Request;
use App\Repositories\FollowRepository;

class FollowController extends BaseController
{
    /**
     * @param Request $request
     * @param FollowRepository $followRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function list (Request $request, FollowRepository $followRepository)
    {
        $params = $request->all();
        $list = @$followRepository->getList($params);
        return $this->success($list);
    }

    /**
     * @param Request $request
     * @param FollowRepository $followRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function save (Request $request, FollowRepository $followRepository)
    {
        $allParams = $request->all();
        $rst = @$followRepository->save($allParams);
        if ($rst) {
            return $this->success([]);
        }
        return $this->error(405, '保存失败，请稍后再试');
    }

    /**
     * @param Request $request
     * @param FollowRepository $followRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function getStockInfo (Request $request, FollowRepository $followRepository)
    {
        $code = $request->get('code');
        $data = @$followRepository->getStockInfoByCode($code);
        if ($data) {
            return $this->success($data);
        } else {
            return $this->error(401, '信息获取失败，请稍后再试');
        }
    }


    /**
     * @param Request $request
     * @param FollowRepository $followRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function getFollowInfo (Request $request, FollowRepository $followRepository)
    {
        $id = $request->get('id');
        $data = @$followRepository->getFollowInfo($id);
        if ($data) {
            return $this->success($data);
        } else {
            return $this->error(401, '信息获取失败，请稍后再试');
        }
    }

    /**
     * @param Request $request
     * @param FollowRepository $followRepository
     */
    /*public function updateHightestAndLowestPrice(Request $request, FollowRepository $followRepository) {
        $isOpen = $request->get('open');
        $followRepository->updateHightestAndLowestPrice();
    }*/
}
